var gulp = require('gulp'),
    sass = require('gulp-sass'),
    minifycss = require('gulp-minify-css'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    rename = require('gulp-rename'),
    imagemin = require('gulp-imagemin'),
    jshint = require('gulp-jshint'),
    plumber = require('gulp-plumber');

gulp.task('dist-app-html', function () {
    gulp.src('app/**/*.html')
        .pipe(plumber())
        .pipe(gulp.dest('D:/superstring/www/default/ie6+/'))
});

gulp.task('dist-app-scss', function () {
    gulp.src(['app/scss/**/*.scss', '!app/scss/**/*-old-ie.scss'])
        .pipe(plumber())
        .pipe(concat('index.min.css'))
        .pipe(sass())
        .pipe(minifycss())
        .pipe(gulp.dest('D:/superstring/www/default/ie6+/'))

    gulp.src('app/**/*-old-ie.scss')
        .pipe(plumber())
        .pipe(concat('index-old-ie.min.css'))
        .pipe(sass())
        .pipe(minifycss())
        .pipe(gulp.dest('D:/superstring/www/default/ie6+/'))
});

gulp.task('dist-app-js', function () {
    gulp.src('app/**/*.js')
        .pipe(plumber())
        .pipe(jshint('.jshintrc'))
        .pipe(jshint.reporter('default'))
        .pipe(uglify())
        .pipe(gulp.dest('D:/superstring/www/default/ie6+/'));
});

gulp.task('dist-superstring-rdmp-json', function () {
    gulp.src('superstring-rdmp/**/*.json')
        .pipe(jshint.reporter('default'))
        .pipe(gulp.dest('D:/superstring/www/default/superstring-rdmp/'));
});

gulp.task('dist', function () {
    gulp.src('bower_components/**')
        .pipe(plumber())
        .pipe(gulp.dest('D:/superstring/www/default/ie6+/lib/'));

    gulp.src('lib/**')
        .pipe(plumber())
        .pipe(gulp.dest('D:/superstring/www/default/ie6+/lib/'));

    gulp.src('superstring-rdmp/**')
        .pipe(plumber())
        .pipe(gulp.dest('D:/superstring/www/default/superstring-rdmp/'));

    gulp.src('image/**/*.jpg')
        .pipe(plumber())
        .pipe(imagemin())
        .pipe(gulp.dest('D:/superstring/www/default/image/'));

    gulp.src('image/**/*.png')
        .pipe(plumber())
        .pipe(imagemin())
        .pipe(gulp.dest('D:/superstring/www/default/image/'));

    gulp.src('image/**/*gif')
        .pipe(plumber())
        .pipe(imagemin())
        .pipe(gulp.dest('D:/superstring/www/default/image/'));
});

gulp.task('default', ['dist-app-html', 'dist-app-scss', 'dist-app-js', 'dist'], function () {
});

gulp.task('watch', ['default'], function () {
    gulp.watch('app/**/*.html', ['dist-app-html']);
    gulp.watch('app/scss/**/*.scss', ['dist-app-scss']);
    gulp.watch('app/**/*.js', ['dist-app-js']);
    gulp.watch('superstring-rdmp/**/*.json', ['dist-superstring-rdmp-json']);
});